<?php
	define('IN_T',true);
	require("../source/include/init.php");

    $view_uuid = Common::sfilter($_REQUEST['view']);
    //查询imgagesmain
	$sql = "SELECT w.pk_works_main,w.pk_user_main,w.cdn_host,p.hotspot,p.scene_group,p.definition ".
		   "FROM ".$Base->table('worksmain')." w ".
		   "LEFT JOIN ".$Base->table('pano_config')." p ON w.pk_works_main = p.pk_works_main ".
	       "WHERE w.view_uuid = '$view_uuid'";
    $worksmain = $Db->query($sql,'Row');
	if (empty($worksmain)) {
		die("未找到相关项目");
	}
	//是否有全景媒体标签
	if($Db->query("select id from ".$Base->table('tag_works')." where works_id = ".$worksmain['pk_works_main']." and tag_id=62 limit 1")){
		$tp->assign('is_tag',1);
	}
	$scene_group = $Json->decode($worksmain['scene_group']);
	$groups = $scene_group['sceneGroups'];
	if (empty($groups)) {
		$sql = "SELECT i.view_uuid AS viewuuid , i.filename AS sceneTitle ,i.thumb_path AS imgPath ".
		       "FROM ".$Base->table('imgsmain')."i ".
			   "LEFT JOIN ".$Base->table('imgs_works')." iw ON i.pk_img_main = iw.pk_img_main ".
			   "WHERE iw.pk_works_main =".$worksmain['pk_works_main']." ".
			   "order by iw.pk_img_main asc";
		$scenes = $Db->query($sql);
		$groups[]['scenes'] = $scenes;
	}
	
	$size = sizeof($groups);
	foreach ($groups as  $g) {
		foreach ($g['scenes'] as $k => $s) {
			$sql = "SELECT levels,pk_img_main,pk_user_main,img_desc,replace_id FROM ".$Base->table('imgsmain')."WHERE view_uuid = '".$s['viewuuid']."'";
			$img = $Db->query($sql,'Row');
			$s['levels'] = explode(",", $img['levels']);
			$s['pk_img_main'] = $img['pk_img_main'];
			$s['lcount'] = sizeof($s['levels']);
			$s['img_desc'] = $img['img_desc'];
			$s['pk_user_main']= $img['pk_user_main'];
			$s['scene_name'] = $s['viewuuid'];
			if ($img['replace_id']>0) {
				$replace = $Db->query("SELECT pk_user_main,levels,view_uuid,thumb_path FROM ".$Base->table('imgsmain')." WHERE pk_img_main = ".$img['replace_id'],'Row');
				$s['levels'] = explode(",", $replace['levels']);
				$s['viewuuid'] = $replace['view_uuid'];
				$s['pk_user_main'] = $replace['pk_user_main'];
				$s['imgPath'] = $replace['thumb_path'];
			}
			if ($k==0 && $size>1) 
				$s['album'] = $g['groupName'];
			$scenesRes[] = $s;
		}
	}
	//print_r($scenesRes);die;
	//print_r($worksmain);die;
	require_once ROOT_PATH.'plugin/plugin_init_function.php';
	plugin_get_plugins("view",true);
	
	$cdn_host = empty($worksmain['cdn_host'])?$_lang['cdn_host']:$worksmain['cdn_host'];
	$tp->assign('cdn_host',$cdn_host);
	//$tp->assign('prefix',$cdn_host.$worksmain['pk_user_main'].'/works');
	$tp->assign('scenesRes',$scenesRes);
	$tp->assign('hotspot',$Json->decode($worksmain['hotspot']));
	$tp->assign('definition',$worksmain['definition']);	//是否高清
	$tp->assign('startscene',Common::sfilter($_REQUEST['startscene']));
	$tp->setTemplateDir(ROOT_PATH.'tour');
	$tp->display('tour.xml');
?>